package edu.xpu.compute.recommend.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import edu.xpu.compute.recommend.entity.SysBook;
import edu.xpu.compute.recommend.entity.SysBookPopular;
import edu.xpu.compute.recommend.repository.SysBookPopularRepository;

@Service
@Transactional(readOnly=true)
public class SysBookPopularService {
	@Autowired
	private SysBookPopularRepository sysBookPopularRepository;
	@Autowired
	private SysBookService sysBookService;
	

	public List<SysBook> getAll() {
		List<SysBookPopular> list = sysBookPopularRepository.findAll();
		List<SysBook> result = new ArrayList<SysBook>();
		if (list != null && list.size() != 0) {
			for (SysBookPopular sysBookPopular : list) {
				SysBook sysBook = sysBookService.get(sysBookPopular.getBookGuid());
				if (sysBook != null) {
					result.add(sysBook);
				}
			}
		}
		return result;
	}
}
